﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Web.Security;
using System.Web.Configuration;
using System.Configuration;
using Business;
using DataAccess;
using SubSonic;


public partial class User_Shares_UploadDocuments : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Lblstatus.Text = "";
        if (!IsPostBack)
        {
            var thisUser = HttpContext.Current.User;

            if (thisUser.IsInRole("Admin") || thisUser.IsInRole("Employer") || thisUser.IsInRole("edituser"))
            {
                GridViewContracts2.Visible = false;
                SelectContract2.Visible = true;
                TextBox1.Visible = true;
                RequiredFieldValidator1.Enabled = true;
                Label20.Visible = true;
                TextBox1.Visible = true;
                MultiViewAdmin.ActiveViewIndex = 0;
                Label5.Visible = true;
                ButtonCancelAdmin.Visible = true;
            }
            else if (thisUser.IsInRole("FourthFactor"))
            {
                Label5.Visible = false;

                GridViewContracts2.DataSource = DataAccess.TblContract.FetchByParameter(DataAccess.TblContract.Columns.FourthFactorUserId, Membership.GetUser().ProviderUserKey, SubSonic.OrderBy.Asc("ContractDate"));
                GridViewContracts2.DataBind();
                GridViewContracts2.Visible = true;
                SelectContract2.Visible = false;
                TextBox1.Visible = false;
                MultiViewAdmin.ActiveViewIndex = -1;
                TextBox1.Visible = false;
                RequiredFieldValidator1.Enabled = false;
                Label20.Visible = false;
                ButtonCancelAdmin.Visible = false;
            }
            else if (thisUser.IsInRole("BonyadShahrestan"))
            {
                Label5.Visible = false;
                IDataReader dr = DataAccess.TblUserDetail.FetchByParameter(DataAccess.TblUserDetail.Columns.UserId,Membership.GetUser().ProviderUserKey);
                dr.Read();
                Guid cityid=new Guid( dr["CityId"].ToString());
                GridViewContracts2.DataSource = Business.CommonCalculations.SelectProjectsByCity(cityid);
                GridViewContracts2.DataBind();
                GridViewContracts2.Visible = true;
                SelectContract2.Visible = false;
                TextBox1.Visible = false;
                MultiViewAdmin.ActiveViewIndex = -1;
                TextBox1.Visible = false;
                RequiredFieldValidator1.Enabled = false;
                Label20.Visible = false;
                ButtonCancelAdmin.Visible = false;
            }
            else
            {
                MultiViewAdmin.ActiveViewIndex = -1;
            }
        }
    }

    protected void GridViewContracts2_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        try
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                Business.Calender cal = new Business.Calender();
                string pdate = cal.MiladiToPersian(Convert.ToDateTime(e.Row.Cells[1].Text));
                e.Row.Cells[1].Text = pdate;
                IDataReader t = DataAccess.TblUserDetail.FetchByParameter(DataAccess.TblUserDetail.Columns.UserId, e.Row.Cells[9].Text);
                if (t.Read())
                {
                    e.Row.Cells[2].Text = t["Name"].ToString() + " / " + t["Family"].ToString();
                    t.Close();
                }

                if (e.Row.Cells[3].Text == bool.TrueString)
                    e.Row.Cells[3].Text = "قرارداد مشاوره";
                if (e.Row.Cells[3].Text == bool.FalseString)
                    e.Row.Cells[3].Text = "قرارداد نقشه برداری";
                DataAccess.TblVillage vil = DataAccess.TblVillage.FetchByID(e.Row.Cells[11].Text);
                e.Row.Cells[5].Text = vil.Name;
                DataAccess.TblDehestan deh = DataAccess.TblDehestan.FetchByID(vil.DehstanId);
                e.Row.Cells[6].Text = deh.Name;
                DataAccess.TblBakhsh bakhsh = DataAccess.TblBakhsh.FetchByID(deh.BakhshId);
                e.Row.Cells[7].Text = bakhsh.Name;
                DataAccess.TblCity city = DataAccess.TblCity.FetchByID(bakhsh.CityId);
                e.Row.Cells[8].Text = city.Name;
                e.Row.Cells[9].Visible = false;
                e.Row.Cells[11].Visible = false;
            }
        }
        catch
        {
        }
    }
    
    protected void GridViewContracts2_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        int id = Convert.ToInt32(e.CommandArgument);
        switch (e.CommandName)
        {
            case "Select":
                Guid idc = new Guid(GridViewContracts2.DataKeys[id].Value.ToString());

                IDataReader dr = DataAccess.TblContract.FetchByParameter(DataAccess.TblContract.Columns.Id, idc);
                //if(dr.Read())
                //{ 
                dr.Read();
                Session["contractid"] = idc;
                MultiViewAdmin.ActiveViewIndex = 1;
                GridViewContracts2.Visible = false;
                Business.Calender c = new Calender();
                LblDate.Text =c.MiladiToPersian(Convert.ToDateTime( dr["ContractDate"].ToString()));
                DataAccess.TblVillage t = DataAccess.TblVillage.FetchByID(dr["VillageId"].ToString());
                lblvilname.Text = t.Name;
                LblConNum.Text = dr["ContractNumber"].ToString();
                MultiViewAdmin.ActiveViewIndex = 1;
                if (dr["ContractType"].ToString() == bool.TrueString)
                    Session["Role"] = "Advisor";
                if (dr["ContractType"].ToString() == bool.FalseString)
                    Session["Role"] = "Surveyor";
                SubSonic.Query q = DataAccess.TblTask.CreateQuery();
                q.QueryType = SubSonic.QueryType.Select;
                q.AddWhere(DataAccess.TblTask.Columns.ContractId, idc);
                q.AddWhere(DataAccess.TblTask.Columns.IsDonei, bool.TrueString);
                IDataReader dr1 = q.ExecuteReader();
                int i = 0;
                if (dr1 != null)
                {
                    while (dr1.Read())
                    {
                        i += 1;
                    }
                }
                dr1.Close();

                if (dr["ContractType"].ToString() == bool.TrueString)
                {


                    SubSonic.Query qad = DataAccess.TblStepsAdvisor.CreateQuery();
                    qad.QueryType = SubSonic.QueryType.Select;
                    qad.BETWEEN_VALUES("Priority", 0, i + 1);
                    qad.OrderBy = SubSonic.OrderBy.Asc("Priority");

                    DataList1.DataSource = qad.ExecuteReader();
                    DataList1.DataBind();
                }
                if (dr["ContractType"].ToString() == bool.FalseString)
                {
                    SubSonic.Query qad = DataAccess.TblStepsSurveyor.CreateQuery();
                    qad.QueryType = SubSonic.QueryType.Select;
                    qad.BETWEEN_VALUES("Priority", 0, i + 1);
                    qad.OrderBy = SubSonic.OrderBy.Asc("Priority");

                    DataList1.DataSource = qad.ExecuteReader();
                    DataList1.DataBind();
                }
                dr.Close();
                break;
        }
    }

    protected void RadioButtonListSelector_SelectedIndexChanged(object sender, EventArgs e)
    {
        //RadioButtonList r=(RadioButtonList) LoginView2.FindControl("RadioButtonListSelector");
        //MultiView m = (MultiView)LoginView2.FindControl("MultiView1");
        //if (r.SelectedItem.Value == "Village")
        //{
        //    m.ActiveViewIndex = 0;
        //}
        //else
        //{
        //    m.ActiveViewIndex = 1;
        //}
    }

    //protected void GridViewContracts_RowDataBound(object sender, GridViewRowEventArgs e)
    //{
    //    try
    //    {
    //        if (e.Row.RowType
    //             == DataControlRowType.DataRow)
    //        {
    //            Guid g = new Guid(e.Row.Cells[3].Text);

    //            IDataReader dr = (IDataReader)DataAccess.TblVillage.FetchByParameter(DataAccess.TblVillage.Columns.Id, SubSonic.Comparison.Equals, g);
    //            dr.Read();
    //            e.Row.Cells[3].Text = dr["Name"].ToString();
    //            dr.Close();
    //            string pdate = new Business.Calender().MiladiToPersian(Convert.ToDateTime(e.Row.Cells[1].Text));
    //            e.Row.Cells[1].Text = pdate;
    //        }
    //    }
    //    catch
    //    {
    //    }
    //}
    
    protected void DataList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        try
        {
            Guid contractid = new Guid(Session["contractid"].ToString());
            if (DataList1.SelectedItem.ItemIndex < 0)
            {
                Session["stepid"] = null;
            }
            else
            {
                SubSonic.Query qad = DataAccess.TblTask.CreateQuery();
                qad.QueryType = SubSonic.QueryType.Select;
                if ((Session["Role"].ToString() == "Advisor"))
                    qad.AddWhere("AdvisorStepId", SubSonic.Comparison.Equals, DataList1.SelectedValue);
                if ((Session["Role"].ToString() == "Surveyor"))
                    qad.AddWhere("SurveyorStepId", SubSonic.Comparison.Equals, DataList1.SelectedValue);
                qad.AddWhere("ContractId", SubSonic.Comparison.Equals, contractid);
                IDataReader dr = qad.ExecuteReader();
                if (dr.Read())
                {
                    string Desc = dr["Status"].ToString();
                    LblDesc.Text = Desc;
                }
                dr.Close();
                Session["stepid"] = DataList1.SelectedValue;
            }
        }
        catch
        { }
    }

    protected void ButtonCancelAdmin_Click(object sender, EventArgs e)
    {
        MultiViewAdmin.ActiveViewIndex = 0;
    }

    protected void Button6_Click(object sender, EventArgs e)
    {
    }

    protected void Multifileupload1_click(object sender, FileCollectionEventArgs e)
    {
        string folder = ConfigurationManager.AppSettings["saveFolder"];
        var thisUser = HttpContext.Current.User;
        Guid contractid = new Guid(Session["contractid"].ToString()); 
        DataAccess.TblContract con=new DataAccess.TblContract();
        con=DataAccess.TblContract.FetchByID(contractid);
        string s = TextBox1.Text;
        DateTime date = DateTime.Now;
        if (s != String.Empty)
        {
            string[] split = s.Split(new Char[] {'/'});
            Business.Calender calender = new Business.Calender();
           date = calender.PersianToMiladi(split[0].ToString(), split[1].ToString(), split[2].ToString());
        }
        DateTime dateOfTask=DateTime.Now;
        if (thisUser.IsInRole("Admin") || thisUser.IsInRole("Employer"))
        {
            if (date.ToString().Trim() != String.Empty)
            {
                dateOfTask = date;
            }
        }

        if (Session["stepid"] == null)
        {
            Lblstatus.Text = " <script>alert('. لطفا ابتدا مرحله مورد نظر را انتخاب کنید ')</script>";
        }
        else
        {
            Guid stepid = new Guid(Session["stepid"].ToString());

            if (Session["Role"].ToString() == "Advisor")
            {
                SubSonic.Query qad = DataAccess.TblTask.CreateQuery();
                qad.QueryType = SubSonic.QueryType.Select;
                qad.AddWhere("AdvisorStepId", SubSonic.Comparison.Equals, stepid);
                qad.AddWhere("ContractId", SubSonic.Comparison.Equals, contractid);
                IDataReader dr = qad.ExecuteReader();
                dr.Read();
                Guid taskid = new Guid(dr["ID"].ToString());
                dr.Close();
                if (thisUser.IsInRole("admin") || thisUser.IsInRole("Employer"))
                {
                    if (TextBox1.Text != "")
                    {
                        bool result = FileTools.SaveFiles(e, HttpContext.Current, folder, taskid, Guid.Empty, date);
                        if (result == true)
                        {
                            SubSonic.Query update = DataAccess.TblTask.CreateQuery();
                            update.QueryType = SubSonic.QueryType.Update;
                            update.AddUpdateSetting(DataAccess.TblTask.Columns.DateX,dateOfTask );
                            update.AddUpdateSetting(DataAccess.TblTask.Columns.IsDonei, true);
                            update.AddUpdateSetting(DataAccess.TblTask.Columns.UserName, Membership.GetUser().UserName);
                            update.AddUpdateSetting(DataAccess.TblTask.Columns.DelayDays, Business.DelayCalculations.Delay(taskid, dateOfTask));
                            update.AddWhere(DataAccess.TblTask.Columns.Id, taskid);
                            update.Execute();
                             Business.Notification n = new Notification();
                            if (con.FourthFactorUserId!=null)
                            n.SaveInnerNotific(contractid, stepid, true,new Guid(con.FourthFactorUserId.ToString()));
                            else
                                Lblstatus.Text = " <script>alert('. عامل چهاراین قرارداد برای ارسال پیغام تعریف نشده است ')</script>";
                    
                            n.SaveInnerNotific(contractid, stepid, true, con.UserId);
                            
                            if (n.findbonyadshahrestan(contractid)!=Guid.Empty)
                            n.SaveInnerNotific(contractid, stepid, true, n.findbonyadshahrestan(contractid));
                            else
                                Lblstatus.Text = " <script>alert('. بنیاد شهرستان این قرارداد برای ارسال پیغام تعریف نشده است ')</script>";
                            Lblstatus.Text = " <script>alert('.فایل های شما با موفقیت ارسال شد ')</script>";
                            List<string> userids = new List<string>();
                            userids.Add(con.FourthFactorUserId.ToString());
                            userids.Add( con.UserId.ToString());
                            userids.Add(n.findbonyadshahrestan(contractid).ToString());
                            string[] mobiles = n.FindMobile(userids);
                            SendSmS(mobiles);
                        }
                        if (result == false)
                        {
                            Lblstatus.Text = " <script>alert('. ارسال فایل های شما با خطا مواجه شد ')</script>";
                        }

                    }
                    else
                    {
                        Lblstatus.Text = " <script>alert('. لطفا تاریخ را وارد کنید ')</script>";
                    }
                }
                else if (thisUser.IsInRole("fourthfactor") || thisUser.IsInRole("BonyadShahrestan"))
                {
                    bool result = FileTools.SaveFiles(e, HttpContext.Current, folder, taskid, Guid.Empty, DateTime.Now);
                    if (result == true)
                    {
                        SubSonic.Query update = DataAccess.TblTask.CreateQuery();
                        update.QueryType = SubSonic.QueryType.Update;
                        update.AddUpdateSetting(DataAccess.TblTask.Columns.DateX, DateTime.Now.ToString());
                        update.AddUpdateSetting(DataAccess.TblTask.Columns.IsDonei, true);
                        update.AddUpdateSetting(DataAccess.TblTask.Columns.UserName, Membership.GetUser().UserName);
                        update.AddUpdateSetting(DataAccess.TblTask.Columns.DelayDays, Business.DelayCalculations.Delay(taskid , dateOfTask));
                        update.AddWhere(DataAccess.TblTask.Columns.Id, taskid);
                        update.Execute();
                       
                        Business.Notification n = new Notification();
                        if (con.FourthFactorUserId != null)
                            n.SaveInnerNotific(contractid, stepid, true, new Guid(con.FourthFactorUserId.ToString()));
                        else
                            Lblstatus.Text = " <script>alert('. عامل چهاراین قرارداد برای ارسال پیغام تعریف نشده است ')</script>";

                        n.SaveInnerNotific(contractid, stepid, true, con.UserId);
                        if (n.findbonyadshahrestan(contractid) != Guid.Empty)
                            n.SaveInnerNotific(contractid, stepid, true, n.findbonyadshahrestan(contractid));
                        else
                            Lblstatus.Text = " <script>alert('. بنیاد شهرستان این قرارداد برای ارسال پیغام تعریف نشده است ')</script>";
                        Lblstatus.Text = " <script>alert('.فایل های شما با موفقیت ارسال شد ')</script>";

                        List<string> userids = new List<string>();
                        if(thisUser.IsInRole("BonyadShahrestan"))
                        userids.Add(con.FourthFactorUserId.ToString());
                        userids.Add(con.UserId.ToString());
                        if (thisUser.IsInRole("fourthfactor"))
                        userids.Add(n.findbonyadshahrestan(contractid).ToString());
                        string[] mobiles = n.FindMobile(userids);
                        SendSmS(mobiles);

                    }
                    if (result == false)
                    {
                        Lblstatus.Text = " <script>alert('. ارسال فایل های شما با خطا مواجه شد ')</script>";
                    }
                }

            }

            if (Session["Role"].ToString() == "Surveyor")
            {
                //SubSonic.Query qad1 = DataAccess.TblTask.CreateQuery();
                Query qad1 = new Query(DataAccess.TblTask.Schema);
                TblTaskCollection taskCollection = new TblTaskCollection();
                qad1.QueryType = QueryType.Select;
                qad1.AddWhere(TblTask.Columns.SurveyorStepId, SubSonic.Comparison.Equals, stepid)
                    .AND(TblTask.Columns.ContractId, SubSonic.Comparison.Equals, contractid);
                taskCollection.LoadAndCloseReader(qad1.ExecuteReader());
                TblTask task = new TblTask();
                task = taskCollection[0];
                Guid taskid1 = task.Id;
                //IDataReader dr1 = qad1.ExecuteReader();
                //dr1.Read();
                //Guid taskid1 = new Guid(dr1["ID"].ToString());
                //dr1.Close();
                if (thisUser.IsInRole("admin") || thisUser.IsInRole("Employer"))
                {
                    if (TextBox1.Text != "")
                    {
                        bool result = FileTools.SaveFiles(e, HttpContext.Current, folder, taskid1, Guid.Empty, date);
                        if (result == true)
                        {


                            SubSonic.Query update = DataAccess.TblTask.CreateQuery();
                            update.QueryType = SubSonic.QueryType.Update;

                            if (thisUser.IsInRole("Admin") || thisUser.IsInRole("Employer"))
                            {
                                update.AddUpdateSetting(DataAccess.TblTask.Columns.DateX, date.ToString());

                            }
                            else
                            {
                                update.AddUpdateSetting(DataAccess.TblTask.Columns.DateX, DateTime.Now.ToString());

                            }

                            update.AddUpdateSetting(DataAccess.TblTask.Columns.IsDonei, true);
                            update.AddUpdateSetting(DataAccess.TblTask.Columns.UserName, Membership.GetUser().UserName);
                            update.AddUpdateSetting(DataAccess.TblTask.Columns.DelayDays, Business.DelayCalculations.Delay(taskid1 , DateTime.Now ));
                            update.AddWhere(DataAccess.TblTask.Columns.Id, taskid1);
                            update.Execute();
                           
                            Business.Notification n = new Notification();
                            if (con.FourthFactorUserId != null)
                                n.SaveInnerNotific(contractid, stepid, false, new Guid(con.FourthFactorUserId.ToString()));
                            else
                                Lblstatus.Text = " <script>alert('. عامل چهاراین قرارداد برای ارسال پیغام تعریف نشده است ')</script>";

                            n.SaveInnerNotific(contractid, stepid, false, con.UserId);
                            if (n.findbonyadshahrestan(contractid) != Guid.Empty)
                                n.SaveInnerNotific(contractid, stepid, false, n.findbonyadshahrestan(contractid));
                            else
                                Lblstatus.Text = " <script>alert('. بنیاد شهرستان این قرارداد برای ارسال پیغام تعریف نشده است ')</script>";
                            Lblstatus.Text = " <script>alert('.فایل های شما با موفقیت ارسال شد ')</script>";
                            List<string> userids = new List<string>();
                            userids.Add(con.FourthFactorUserId.ToString());
                            userids.Add(con.UserId.ToString());
                            userids.Add(n.findbonyadshahrestan(contractid).ToString());
                            string[] mobiles = n.FindMobile(userids);
                            SendSmS(mobiles);
                        }
                        if (result == false)
                        {
                            Lblstatus.Text = " <script>alert('. ارسال فایل های شما با خطا مواجه شد ')</script>";
                        }


                    }
                    else
                    {
                        Lblstatus.Text = " <script>alert('. لطفا تاریخ را وارد کنید ')</script>";
                    }
                }
                else if (thisUser.IsInRole("fourthfactor")||thisUser.IsInRole("BonyadShahrestan"))
                {
                      bool result = FileTools.SaveFiles(e, HttpContext.Current, folder, taskid1, Guid.Empty, DateTime.Now);
                        if (result == true)
                        {


                            SubSonic.Query update = DataAccess.TblTask.CreateQuery();
                            update.QueryType = SubSonic.QueryType.Update;

                         
                                update.AddUpdateSetting(DataAccess.TblTask.Columns.DateX, DateTime.Now.ToString());

                           

                            update.AddUpdateSetting(DataAccess.TblTask.Columns.IsDonei, true);
                            update.AddUpdateSetting(DataAccess.TblTask.Columns.UserName, Membership.GetUser().UserName);
                            update.AddUpdateSetting(DataAccess.TblTask.Columns.DelayDays, Business.DelayCalculations.Delay(taskid1 , dateOfTask));
                            update.AddWhere(DataAccess.TblTask.Columns.Id, taskid1);
                            update.Execute();
                            
                            Business.Notification n = new Notification();
                            if (con.FourthFactorUserId != null)
                                n.SaveInnerNotific(contractid, stepid, false, new Guid(con.FourthFactorUserId.ToString()));
                            else
                                Lblstatus.Text = " <script>alert('. عامل چهاراین قرارداد برای ارسال پیغام تعریف نشده است ')</script>";

                            n.SaveInnerNotific(contractid, stepid, false, con.UserId);
                            if (n.findbonyadshahrestan(contractid) != Guid.Empty)
                                n.SaveInnerNotific(contractid, stepid, false, n.findbonyadshahrestan(contractid));
                            else
                                Lblstatus.Text = " <script>alert('. بنیاد شهرستان این قرارداد برای ارسال پیغام تعریف نشده است ')</script>";
                            Lblstatus.Text = " <script>alert('.فایل های شما با موفقیت ارسال شد ')</script>";
                            List<string> userids = new List<string>();
                            if (thisUser.IsInRole("BonyadShahrestan"))
                                userids.Add(con.FourthFactorUserId.ToString());
                            userids.Add(con.UserId.ToString());
                            if (thisUser.IsInRole("fourthfactor"))
                                userids.Add(n.findbonyadshahrestan(contractid).ToString());
                            string[] mobiles = n.FindMobile(userids);
                            SendSmS(mobiles);
                        }
                        if (result == false)
                        {
                            Lblstatus.Text = " <script>alert('. ارسال فایل های شما با خطا مواجه شد ')</script>";
                        }
                }

            }
        }
    }

    //protected void PersianCalendar1_SelectionChanged(object sender, EventArgs e)
    //{
    //    PopupControlExtender1.Commit(PersianCalendar1.SelectedDatePersian);
    //}

    public void SelectContract_Click(object sender)
    {
        Session["contractid"] = SelectContract2.Contractid.ToString();
        LblDate.Text = SelectContract2.Date;
        lblvilname.Text = SelectContract2.VillageName;
        LblConNum.Text = SelectContract2.ContractNumber;
        MultiViewAdmin.ActiveViewIndex = 1;
        Session["Role"] = SelectContract2.Role;
        SubSonic.Query q = DataAccess.TblTask.CreateQuery();
        q.QueryType = SubSonic.QueryType.Select;
        q.AddWhere(DataAccess.TblTask.Columns.ContractId, SelectContract2.Contractid);
        q.AddWhere(DataAccess.TblTask.Columns.IsDonei, bool.TrueString);
        IDataReader dr = q.ExecuteReader();
        int i = 0;
        if (dr != null)
        {
            while (dr.Read())
            {
                i += 1;
            }
        }
        dr.Close();

        if (SelectContract2.Role == "Advisor")
        {


            SubSonic.Query qad = DataAccess.TblStepsAdvisor.CreateQuery();
            qad.QueryType = SubSonic.QueryType.Select;
            qad.BETWEEN_VALUES("Priority", 0, i + 1);
            qad.OrderBy = SubSonic.OrderBy.Asc("Priority");

            DataList1.DataSource = qad.ExecuteReader();
            DataList1.DataBind();
        }
        if (SelectContract2.Role == "Surveyor")
        {
            SubSonic.Query qad = DataAccess.TblStepsSurveyor.CreateQuery();
            qad.QueryType = SubSonic.QueryType.Select;
            qad.BETWEEN_VALUES("Priority", 0, i + 1);
            qad.OrderBy = SubSonic.OrderBy.Asc("Priority");

            DataList1.DataSource = qad.ExecuteReader();
            DataList1.DataBind();
        }

    }

    protected void TextBox1_TextChanged(object sender, EventArgs e)
    {

    }

    public void SendSmS(string[] D)
    {
        com.sobhsms.www.Service1 s = new com.sobhsms.www.Service1();
        string str = "لطفاهرچه سریعتربه وبسایت www.bonyadmaskanfars.ir/fpm مراجعه بفرمایید.";
      
str = str.Replace("@", Environment.NewLine);
if (D.Length > 0)
{

    long[] r = s.SendPackageMessageConcFast(D, str, "Pwebsrvbnydmskn90");
}
        //Response.Write(r[0].ToString());
    }

    protected void GridViewContracts2_PreRender(object sender, EventArgs e)
    {
        GridViewPreRender(GridViewContracts2);
    }

    private void GridViewPreRender(GridView gridView)
    {
        if (gridView.Rows.Count > 0)
        {
            //This replaces <td> with <th> and adds the scope attribute
            gridView.UseAccessibleHeader = true;

            //This will add the <thead> and <tbody> elements
            gridView.HeaderRow.TableSection = TableRowSection.TableHeader;

            //This adds the <tfoot> element. 
            //Remove if you don't have a footer row
            gridView.FooterRow.TableSection = TableRowSection.TableFooter;
        }
    }
}